package com.erp.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson.JSONObject;
import com.erp.shop.domain.bo.ErpStoreCategoryBrandBo;
import com.erp.shop.domain.vo.ErpStoreCategoryBrandVo;
import com.erp.shop.service.IErpStoreCategoryBrandService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;
import com.ruoyi.shop.api.domain.ErpSellerStoreEmpower;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 店铺可用类目品牌
 *
 * @author erp
 * @date 2023-07-21
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/seller/storeCategoryBrand")
public class ErpStoreCategoryBrandController extends BaseController {

    private final IErpStoreCategoryBrandService iErpStoreCategoryBrandService;
//    private final IAeStoreService aeStoreService;

    /**
     * 查询店铺可用类目品牌列表
     */
    @SaCheckPermission("seller:storeCategoryBrand:list")
    @GetMapping("/list")
    public TableDataInfo<ErpStoreCategoryBrandVo> list(ErpStoreCategoryBrandBo bo, PageQuery pageQuery) {
        return iErpStoreCategoryBrandService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取店铺可用类目品牌详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:storeCategoryBrand:query")
    @GetMapping("/{id}")
    public R<ErpStoreCategoryBrandVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpStoreCategoryBrandService.queryById(id));
    }

    /**
     * 新增店铺可用类目品牌
     */
    @SaCheckPermission("seller:storeCategoryBrand:add")
    @Log(title = "店铺可用类目品牌", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpStoreCategoryBrandBo bo) {
        return toAjax(iErpStoreCategoryBrandService.insertByBo(bo));
    }

    /**
     * 修改店铺可用类目品牌
     */
    @SaCheckPermission("seller:storeCategoryBrand:edit")
    @Log(title = "店铺可用类目品牌", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpStoreCategoryBrandBo bo) {
        return toAjax(iErpStoreCategoryBrandService.updateByBo(bo));
    }

    /**
     * 删除店铺可用类目品牌
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:storeCategoryBrand:remove")
    @Log(title = "店铺可用类目品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpStoreCategoryBrandService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 查询用户授权店铺列表
     */
    @GetMapping("/getEmpowerList")
    public R<List<ErpSellerStoreEmpower>> getEmpowerList() {
        return R.ok(iErpStoreCategoryBrandService.getEmpowerList());
    }

    /**
     * 查询店铺可用类目品牌列表
     */
    @GetMapping("/getBrandListByStoreId")
    public R<Map<String,Object>> getBrandListByStoreId(Long storeId) {
        return R.ok(iErpStoreCategoryBrandService.getBrandListByStoreId(storeId));
    }

    /**
     * @Description: 查询可用类目品牌列表，不区分店铺，只看已上架的品牌，在上传的时候在确认是否有品牌授权
     * @Author: j.zh
     * @Date: 2024/7/4
     * @return
     * @Version: 4.2.0
    **/
    @GetMapping("/getBrandList")
    public R<Map<String,Object>> getBrandList() {
        return R.ok(iErpStoreCategoryBrandService.getBrandList());
    }

    /**
     * 查询店铺可用类目列表
     */
    @GetMapping("/getCatrgoryListByStoreId")
    public R<Object> getCatrgoryListByStoreId(Long storeId) {
    	return R.ok(iErpStoreCategoryBrandService.getCatrgoryListByStoreId(storeId));
    }


    /**
     * 同步店铺品牌数据接口
     */
//    @GetMapping("/getBrandSynchronousByStoreId")
//    public R<Object> getBrandSynchronousByStoreId(Long storeId) {
//        return aeStoreService.getStoreUsableBrand(storeId);
//    }

    @GetMapping("/queryStoreBrandInnerAuth/{categoryId}/{sellerProductId}/{storeId}")
    R<Object> queryStoreBrandInnerAuth(
            @PathVariable("categoryId") Long categoryId,
            @PathVariable("sellerProductId") Long sellerProductId,
                                       @PathVariable("storeId") Long storeId){
        return iErpStoreCategoryBrandService.queryStoreBrand(categoryId,sellerProductId.toString(), storeId);
    }



}
